//
// File:	InputManager.cpp
// Author:	Thomas TISSOT-DUPONT
// Login:	<thomas.tissotdupont@free.fr>
//
// Create:	30/01/2010 at 03:28:34
// Purpose:	
//
#include "Base.hpp"
#include "InputManager.hpp"
#include "Trace.hpp"

//------------------------------------------------------------------
// Constructor / Destructor
//------------------------------------------------------------------
InputManager::InputManager()
{
}

InputManager::~InputManager()
{
}

//------------------------------------------------------------------
// Add Input
//------------------------------------------------------------------
bool InputManager::AddInput(IInput *pInput)
{
	//Do not add an input twice
	std::list<IInput *>::const_iterator it = m_inputHandlers.begin();
	std::list<IInput *>::const_iterator ite = m_inputHandlers.end();
	for (; it != ite; ++it)
	{
		if ((*it)->GetType() == pInput->GetType())
		{
			return false;
		}
	}
	m_inputHandlers.push_back(pInput);
	return true;
}

//------------------------------------------------------------------
// Update
//------------------------------------------------------------------
void InputManager::Update()
{
	if (GlobalVariables::GuiManager::Get().IsVisible())
		return;
	std::list<IInput *>::const_iterator it = m_inputHandlers.begin();
	std::list<IInput *>::const_iterator ite = m_inputHandlers.end();
	for (; it != ite; ++it)
	{
		(*it)->Update();
	}
}

//------------------------------------------------------------------
// Has Input
//------------------------------------------------------------------
bool InputManager::HasInput(const std::string &inputAction) const
{
	std::list<IInput *>::const_iterator it = m_inputHandlers.begin();
	std::list<IInput *>::const_iterator ite = m_inputHandlers.end();
	for (; it != ite; ++it)
	{
		if ((*it)->HasInput(inputAction) == true)
		{
			return true;
		}
	}
	return false;
}
